package com.gwc.filter;

import javax.servlet.*;
import java.io.IOException;

public class LifeCycleFilter implements Filter {
    /*   名字       启动时间     执行次数
    * 1、构建函数    项目启动      1
    * 2、初始化函数   构造完毕      1
    * 3、过滤请求    每次请求      多次
    * 4、销毁函数    服务关闭时    1
    * */

    public LifeCycleFilter(){
        System.out.println("LifeCycleFilter构造函数");
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        String dateTimePattern = filterConfig.getInitParameter("dateTimePattern");
        System.out.println("LifeCycleFilter初始化dateTimePattern:"+dateTimePattern);
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("LifeCycleFilter构造函数继续处理");
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {
        System.out.println("LifeCycleFilter销毁");
    }
}
